package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-31
 * Time: 16:13
 */

/**
 * 如果，自定义异常继承于Exception，此时是编译时异常（受查异常），那么就要用throws声明，或者在这个方法直接处理
 *
 * 所说的处理就是： try {
 *             login.loginFo("234", "g");
 *
 *         }catch (UserException e) {
 *             e.printStackTrace();
 *         }catch (PassWardException e) {
 *             e.printStackTrace();
 *         }finally {
 *
 *         }
 */
class login {
    private String userName;
    private String passWord;


    public  void loginFo(String userName, String passWord)throws UserException,PassWardException{
        if (!this.userName.equals(userName)) {
            throw new UserException("抛出自定义，的用户名错误异常");

        }

        if (!this.passWord.equals(passWord)) {

            throw new PassWardException("抛出密码自定义，的用密码错误异常");

        }

        System.out.println("登录成功！");
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
}



public class TestException {
    public static void main(String[] args) throws UserException {
        login login = new login();
        login.setPassWord("321");
        login.setUserName("haha");
        login.loginFo("haha", "323");

        /*try {
            login.loginFo("haha", "323");

        }catch (UserException e) {
            e.printStackTrace();
        }catch (PassWardException e) {
            e.printStackTrace();
        }finally {

        }*/
    }
}
